package com.gw.booking.common;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Pagenation implements Serializable {

	private static final long serialVersionUID = 5105577890127900314L;
	
	// 参数传入
	// 当前页面号码
	private int page;
	// 页面大小  一个页面显示多少个数据
	private int size;
	
	// 数据总数
	private long total;
	// 查询数据集合
	private List<?> list;
	
	// 可以根据上面的属性  page, size, total 计算出
	private int pageCount; // 页面总数
    private int startRow;// 当前页面开始行, 第一行是0行
    private int first = 1;// 第一页 页号
    private int last;// 最后页 页号
    private int next;// 下一页 页号
    private int prev;// 前页 页号
    private int start;// 页号式导航, 起始页号
    private int end;// 页号式导航, 结束页号
    private int numCount = 10;// 页号式导航, 最多显示页号数量为numCount+1;这里显示11页。
    public List<String> showPages = new ArrayList<String>(); //要显示的页号
    private Object queryClass;//保存查询条件
    private String queryUrl;
    
    
    public Pagenation(){
    	
    }
    
    public Pagenation(int page, int size, long total){
    	if(page <= 0){
    		page = 1;
    	}
    	this.page = page;
    	this.size = size;
    	this.total = total;
    	
    	this.pageCount = (int) Math.ceil((double) total / size);
        this.page = Math.min(this.page, pageCount);
        this.page = Math.max(1, this.page);

        this.startRow = (this.page - 1) * size;
        this.last = this.pageCount;
        this.next = Math.min(this.pageCount, this.page + 1);
        this.prev = Math.max(1, this.page - 1);
    	
        // 计算page 控制
        start = Math.max(this.page - numCount / 2, first);
        end = Math.min(start + numCount, last);
        if (end - start < numCount) {
            start = Math.max(end - numCount, 1);
        }
        for(int i = start; i <= end; i++){
            showPages.add(String.valueOf(i));
        }
        
    }
    
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		
		if(page <= 0){
			this.page = 1;
		}
		else{
			this.page = page;
		}
	}
	
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	public long getTotal() {
		return total;
	}
	public void setTotal(long total) {
		this.total = total;
	}
	
	@SuppressWarnings("rawtypes")
	public List getList() {
		return list;
	}
	
	@SuppressWarnings("rawtypes")
	public void setList(List list) {
		this.list = list;
	}
	
	public int getPageCount() {
		return pageCount;
	}
	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}
	public int getStartRow() {
		return startRow;
	}
	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}
	public int getFirst() {
		return first;
	}
	public void setFirst(int first) {
		this.first = first;
	}
	public int getLast() {
		return last;
	}
	public void setLast(int last) {
		this.last = last;
	}
	public int getNext() {
		return next;
	}
	public void setNext(int next) {
		this.next = next;
	}
	public int getPrev() {
		return prev;
	}
	public void setPrev(int prev) {
		this.prev = prev;
	}
	public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getEnd() {
		return end;
	}
	public void setEnd(int end) {
		this.end = end;
	}
	public int getNumCount() {
		return numCount;
	}
	public void setNumCount(int numCount) {
		this.numCount = numCount;
	}
	public List<String> getShowPages() {
		return showPages;
	}
	public void setShowPages(List<String> showPages) {
		this.showPages = showPages;
	}
	public Object getQueryClass() {
		return queryClass;
	}
	public void setQueryClass(Object queryClass) {
		this.queryClass = queryClass;
	}
	public String getQueryUrl() {
		return queryUrl;
	}
	public void setQueryUrl(String queryUrl) {
		this.queryUrl = queryUrl;
	}
	
	
	
	

}
